package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class FindOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("查找图书....");
        System.out.println("请输入你要查找的书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        //遍历书架

        int size = bookList.getSize();
        for(int i = 0;i<size;i++){
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())){
                System.out.println("找到了，在"+i+"位置。");
                System.out.println(book);
                return;
            }
        }
        System.out.println("很抱歉，没有找到这本书。");
    }
}
